<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * 模块:通用类
 * 开发:胡耆英
 * 创建日期: 2011-05-16
 * 
 */
class Common 
{
    private $CI;
    
    public function __construct()
    {
        $this->CI = & get_instance();
    }
}

/*定义一个样式的决定路径*/
define('__THEMES__',base_url().'application/views/');
/*
 * 跳转函数
 * $message //需要显示的信息
 * $url 需要跳转到的地址
 * $method 跳转方式,空为网页
 */
function show_message($message,$url,$method='')
{
    $CI = &get_instance();
    if($method=='')
    {
        echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
        echo '<script type="text/javascript">alert("'.$message.'")</script>';
        echo '<script type="text/javascript">window.location.href="'.$url.'";</script>';
        exit();
	}
	elseif($method==1)
	{
        $data['message'] = $message;
        $data['url'] = $url;
        $CI->load->view('showmessage', $data, FALSE);
	}
    return false;
}

//获取模型
function M($name)
{
	$CI = &get_instance();
	$CI->load->model('model_model');
	return $CI->model_model->table($name);
}

//从url获取数据
function get_data_from_url($url)
{
	if(function_exists('file_get_contents'))
	{
		set_time_limit(0);
		$file_contents = file_get_contents($url);
	}
	else
	{
		$ch = curl_init();
		$timeout = 5;
		curl_setopt ($ch, CURLOPT_URL, $url);
		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
		$file_contents = curl_exec($ch);
		curl_close($ch);
	}
	return $file_contents;
}
//将json返回的数组转换成标准的数组
function object_array($array)
{
	if(is_object($array))
	{
		$array = (array)$array;
	}
	if(is_array($array))
	{
		foreach($array as $key=>$value)
		{
			$array[$key] = object_array($value);
		}
	}
	return $array;
}
?>